import { _decorator, Component, Node, v3, Vec3 } from 'cc';
import { ActorManager } from '../level/ActorManager';
const { ccclass, property } = _decorator;

let temp:Vec3 = v3();

@ccclass('CameraContronller')
export class CameraContronller extends Component {

    initDirection: Vec3 = null;

    start() {

    }

    update(deltaTime: number) {
        const target = ActorManager.instance.playActor;
        if(target == null)
            return;

        if(this.initDirection == null){
            this.initDirection = v3();
            Vec3.subtract(this.initDirection, this.node.worldPosition, target.node.worldPosition);
        }else{
            Vec3.add(temp, target.node.worldPosition, this.initDirection);
            this.node.worldPosition = temp;
        }
    }
}

